import { ref } from 'vue'
import { getSource } from '@/apis'
import { formatObject } from '@/utils/common'

/** 平台模块 */
export function useSource() {
  const sourceList = ref([])

  const getSourceList = async () => {
    const res = await getSource()
    sourceList.value = res.data.list
  }

  // 根据源头ID返回源头名称或其他
  const formatSource = (sourceChatRoomId: number, key = 'name') => {
    return formatObject(unref(sourceList), 'sourceChatRoomId', sourceChatRoomId, key)
  }

  return { sourceList, getSourceList, formatSource }
}
